home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / child.a < prev    next >
Text File  |  1996-07-07  |  2KB  |  122 lines

  1.     INCLUDE    "utility/tagitem.i"
  2.     INCLUDE    "exec/tasks.i"
  3.     INCLUDE    "exec/ports.i"
  4.  
  5.     XREF    _LVOPutMsg
  6.     XREF    _LVOSystemTagList
  7.     XREF    _LVOFreeMem
  8.     XREF    _LVOFindPort
  9.     XREF    _LVOFindTask
  10.     XREF    _LVOAddHead
  11.     XREF    __startup_port
  12.     XREF    __child_fp
  13.     XREF    _LinkerDB
  14.  
  15.     XDEF    __child_startup
  16.     XDEF    __child_startup_end
  17.  
  18.     csect    text,0,,2,2
  19.  
  20.     XREF    __child_command
  21.     XREF    __child_command_len
  22.     XREF    __child_door_name
  23.     XREF    __child_door_name_len
  24.     XREF    __child_exit
  25.     XREF    _DOSBase
  26.     XREF    _startup_message
  27.     XREF    __child_entry
  28.  
  29. * Code executed by a child process. A new copy is created for each child.
  30.  
  31. __child_startup:
  32.     movem.l    d2-d5/a2-a5,-(a7)
  33.     
  34.     lea    _LinkerDB,a4
  35.     move.l    __child_command(a4),d4
  36.     move.l    __child_command_len(a4),d5
  37.     move.l    __child_exit(a4),a2
  38.     move.l    _DOSBase(a4),a3
  39.     move.l    __child_door_name(a4),a5
  40.     move.l    __child_door_name_len(a4),d3
  41.     move.l    __child_fp(a4),d2
  42.  
  43. * Arrange for code to be freed on exit
  44.     sub.l    a1,a1
  45.     move.l    4,a6
  46.     jsr    _LVOFindTask(a6)
  47.     move.l    d0,a0
  48.     lea    TC_MEMENTRY(a0),a0
  49.     move.l    __child_entry(a4),a1
  50.     jsr    _LVOAddHead(a6)
  51.     
  52. * Send startup message to parent    
  53.     move.l    4,a6
  54.     move.l    __startup_port,a0
  55.     lea    _startup_message(a4),a1
  56.     jsr    _LVOPutMsg(a6)
  57.  
  58. * From now on, parent may disappear.
  59.  
  60. * Start command
  61.     tst.l    d5
  62.     beq.s    func
  63.     move.l    a3,a6
  64.     move.l    d4,d1
  65.     lea    notags(pc),a0
  66.     move.l    a0,d2
  67.     jsr    _LVOSystemTagList(a6)
  68.     bra.s    retcode
  69. func:
  70. * Call function (both parm=reg and parm=stack will do)
  71.     move.l    d4,a0
  72.     move.l    d4,-(a7)
  73.     move.l    d2,a1
  74.     jsr    (a1)
  75.     addq    #4,a7
  76. retcode:
  77. * Prepare result code
  78.     lsl.l    #8,d0
  79.     move.l    d0,24(a2)
  80.  
  81. * Send result to parent if he is still there
  82.     move.l    a5,a1
  83.     move.l    4,a6
  84.     jsr    _LVOFindPort(a6)
  85.     tst.l    d0
  86.     beq.s    noemacs
  87.  
  88.     move.l    d0,a0
  89.     move.l    a2,a1
  90.     jsr    _LVOPutMsg(a6)
  91.     bra.s    exit
  92.  
  93. noemacs:
  94. * Free child_exit
  95.     move.l    a2,a1
  96.     moveq    #0,d0
  97.     move.w    MN_LENGTH(a2),d0
  98.     jsr    _LVOFreeMem(a6)
  99.  
  100. exit:
  101. * Free port name
  102.     move.l    a5,a1
  103.     move.l    d3,d0
  104.     jsr    _LVOFreeMem(a6)
  105.  
  106. * Free command
  107.     tst.l    d5
  108.     beq.s    nofree
  109.     move.l    d4,a1
  110.     move.l    d5,d0
  111.     jsr    _LVOFreeMem(a6)
  112.  
  113. nofree:
  114.     movem.l    (a7)+,d2-d5/a2-a5
  115.     rts
  116.  
  117. notags    dc.l    TAG_DONE
  118.  
  119. __child_startup_end:
  120.  
  121.     end
  122.